package com.jacky.ws;

import com.corundumstudio.socketio.SocketIOServer;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SocketIOApp implements CommandLineRunner, DisposableBean {

    private final Logger LOG = LoggerFactory.getLogger(SocketIOApp.class);

    @Resource
    private SocketIOServer socketIOServer;

    public static void main(String[] args) {
        SpringApplication.run(SocketIOApp.class,args);
    }

    @Override
    public void destroy() throws Exception {
        socketIOServer.stop();
        LOG.info("socket server stop...");
    }


    @Override
    public void run(String... args) throws Exception {
        socketIOServer.start();
        LOG.info("socket server start...");
    }
}
